home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ML_BME1.ZIP / ROTATE / V2 / ROTIMG2.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1996-12-21  |  6.0 KB  |  263 lines

  1. {
  2.   PCX-bitmap 2D rotation+zoom
  3.   a wonderful shit by Maple Leaf, 22 Oct 1996
  4.   no fuckin rights reserved.
  5.   -------------------------------------------------------------------------
  6.    ! ! ! ! ! ! ! ! ! ! ! ! ! ! !   WARNING ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
  7.    THIS program does not work ! It was made only to show the big wonderful
  8.    and crappy possibilities that TP/BP x.xx offers in using the 386 asm. >:(
  9.    What the hack, man, didn't they think about "implementing" the 386 instruc-
  10.    tions set into Pascal's ASM ?
  11.    See version ROTIMG3.PAS+ROTASM.ASM for an example which REALLY WORKS !
  12.   -------------------------------------------------------------------------
  13.  
  14.       a  s  s  e  m  b  l  e  r     r  u  l  e  s     !   !   !   !
  15. }
  16.  
  17. uses alloc, bitmap, crt;
  18.  
  19. var pal : array [byte] of record r,g,b:byte end;
  20.     Img : pointer;
  21.     Vscr, OffsVscr: word;
  22.  
  23.     CosTab, SinTab : array [byte] of longint;
  24.     RowOffs : array [0..199] of word;
  25.  
  26. procedure LoadImage;
  27. begin
  28.   if paramcount=0 then begin
  29.     writeln('ROTIMG ImageName.PCX');
  30.     halt
  31.   end;
  32.   img:=LoadPCX(paramstr(1), @pal);  { suppose no errors ! }
  33. end;
  34.  
  35. procedure InitVideo;near;assembler;
  36. asm
  37.   mov ax,13h
  38.   int 10h  { init video mode }
  39.   mov dx,3c8h
  40.   mov al,0
  41.   out dx,al
  42.   inc dx
  43.   mov cx,768
  44.   mov si,offset pal
  45.   rep outsb { set palette }
  46. end;
  47.  
  48. procedure vWait;near;assembler;
  49. asm
  50.     mov dx,3DAh
  51. @1: in al,dx
  52.     test al,8
  53.     jnz @1
  54. @2: in al,dx
  55.     test al,8
  56.     jz @2
  57. end;
  58.  
  59. procedure ShowVScreen;near;assembler;
  60. asm
  61.   push ds
  62.   push es
  63.   mov cx,16000
  64.   mov ax,0A000h
  65.   mov es,ax
  66.   mov di,0
  67.   mov si,di
  68.   mov ds,VScr
  69.   cld
  70.   db 66h; rep movsw
  71.   pop es
  72.   pop ds
  73. end;
  74.  
  75.  
  76. VAR _Ax_, _Ay_ : LongInt;
  77.     _Bx_, _By_ : LongInt;
  78.     _Cx_, _Cy_ : LongInt;
  79.      WW,  WH : LongInt;
  80.      Angle : Byte;  { 256-degrees system }
  81.  
  82.     _lx_, _Ly_:longint;
  83.     _sx_, _Sy_:longint;
  84.  
  85.     HAdvX, HAdvY, VAdvX, VAdvY : longint;
  86.  
  87. procedure ComputeFramePara;
  88. { suppose _Ax_, _Ay_, Angle, WW and WH are initialized }
  89. begin
  90.  
  91.   _Bx_:=_Ax_+trunc(WH*costab[Angle]) div 256;
  92.   _By_:=_Ay_-trunc(WH*sintab[Angle]) div 256;
  93.  
  94.   _Cx_:=_Ax_+trunc(WW*costab[byte(Angle+64 {90 deg})]) div 256;
  95.   _Cy_:=_Ay_-trunc(WW*sintab[byte(Angle+64 {90 deg})]) div 256;
  96.  
  97.   HAdvX:=((_Cx_-_Ax_) shl 16) div 320;
  98.   HAdvY:=((_Cy_-_Ay_) shl 16) div 320;
  99.   VAdvX:=((_Bx_-_Ax_) shl 16) div 200;
  100.   VAdvY:=((_By_-_Ay_) shl 16) div 200;
  101. end;
  102.  
  103. procedure GenHoriz;near;assembler;
  104. asm
  105.   push cx
  106.   {_sx_:=_Lx_; _Sy_:=_Ly_;}
  107.   db 66h; mov ax,word ptr _Lx_
  108.   db 66h; mov bx,word ptr _Ly_
  109.   {for k:=0 to 319 do begin}
  110.   mov cx,320
  111. @Loop2:
  112.     {offsSource:=320*trunc(_Sy_)+trunc(_sx_);}
  113.     db 66h; mov si,bx
  114.     db 66h; ror si,15
  115.     and si,0FFFEh
  116.     db 66h; mov dx,ax
  117.     db 66h; ror dx,16
  118.     mov si,word ptr RowOffs[si]
  119.     add si,dx
  120.     {mem[VScr:offsVscr]:=mem[seg(img^):offsSource];
  121.     inc(OffsVscr);}
  122.     db 64h,8ah,04h { mov al,fs:[si] }
  123.     mov es:[di],al
  124.     inc di
  125.     {_sx_:=_sx_+HAdvX;}
  126.     db 66h; add ax,word ptr HAdvX
  127.     {_Sy_:=_Sy_+HAdvY;}
  128.     db 66h; add bx,word ptr HAdvY
  129.     {if _sx_>319 then _sx_:=_sx_-320;}
  130.     db 66h; cmp ax,0; dw 13fh {13F0000h}
  131.     db 66h; jle @e5
  132.     db 66h; sub ax,0; dw 140h {1400000h}
  133. @e5:{if _sx_<0 then _sx_:=320+_sx_;}
  134.     db 66h; cmp ax,0h; dw 0
  135.     db 66h; jge @e6
  136.     db 66h; add ax,0; dw 140h {1400000h}
  137. @e6:{if _Sy_>199 then _Sy_:=0;}
  138.     db 66h; cmp bx,0; dw 0C7h {0C70000h}
  139.     db 66h; jle @e7
  140.     db 66h; sub bx,0; dw 0C8h {0C80000h}
  141. @e7:{if _Sy_<0 then _Sy_:=199;}
  142.     db 66h; cmp bx,0h; dw 0
  143.     db 66h; jge @e8
  144.     db 66h; add bx,0; dw 0C8h {0C80000h}
  145. @e8:{end;}
  146.     dec cx
  147.     jnz @Loop2
  148.   pop cx
  149. end;
  150.  
  151. procedure GenVert;near;assembler;
  152. asm
  153.   push es
  154.   db 0fh,0a0h {push fs}
  155.   mov es,vScr
  156.   db 8eh,26h;dw 2+offset Img  {mov fs,Img[2]}
  157.   { OffsVscr:=0; }
  158.   mov di,0
  159.   { _lx_:=_Ax_ shl 16; }
  160.   db 66h; mov ax,word ptr _Ax_
  161.   db 66h; shl ax,16
  162.   db 66h; mov word ptr _lx_,ax
  163.   {_Ly_:=_Ay_ shl 16;}
  164.   db 66h; mov ax,word ptr _Ay_
  165.   db 66h; shl ax,16
  166.   db 66h; mov word ptr _Ly_,ax
  167.   {for k:=0 to 199 do begin}
  168.   mov cx,200
  169. @Loop1:
  170.     { GenHoriz(trunc(_lx_),trunc(_Ly_)); }
  171.     call GenHoriz
  172.     {_lx_:=_lx_+VAdvX; }
  173.     db 66h; mov ax,word ptr _lx_
  174.     db 66h; add ax,word ptr VAdvX
  175.     {_Ly_:=_Ly_+VAdvY; }
  176.     db 66h; mov bx,word ptr _Ly_
  177.     db 66h; add bx,word ptr VAdvY
  178.     {if _lx_>319 then _lx_:=0;}
  179.     db 66h; cmp ax,0; dw 13Fh {13F0000h}
  180.     db 66h; jle @e1
  181.     db 66h; sub ax,0; dw 140h {1400000h}
  182. @e1:{if _lx_<0 then _lx_:=319;}
  183.     db 66h; cmp ax,0; dw 0
  184.     db 66h; jge @e2
  185.     db 66h; add ax,0; dw 140h {1400000h}
  186. @e2:{if _Ly_>199 then _Ly_:=0;}
  187.     db 66h; cmp bx,0; dw 0C7h {0C70000h}
  188.     db 66h; jle @e3
  189.     db 66h; sub bx,0; dw 0C8h {0C80000h}
  190. @e3:{if _Ly_<0 then _Ly_:=199;}
  191.     db 66h; cmp bx,0; dw 0
  192.     db 66h; jge @e4
  193.     db 66h; add bx,0; dw 0C8h {0C80000h}
  194. @e4:
  195.     db 66h; mov word ptr _LX_,ax
  196.     db 66h; mov word ptr _LY_,bx
  197.     {end;}
  198.     dec cx
  199.     jnz @Loop1
  200.   db 0fh,0a1h {pop fs}
  201.   pop es
  202. end;
  203.  
  204. procedure DoIt;
  205. begin
  206.  
  207.   WW:=320; WH:=200;
  208.   _Ax_:=0; _Ay_:=0;
  209.   Angle:=191; { approx 270 degrees in a 360-deg system }
  210.  
  211.   repeat
  212.  
  213.     { modify _Ax_, _Ay_, Angle, WW and WH ...}
  214.     {...}
  215.  
  216.     inc(Angle,2);
  217.  
  218.     inc(_Ax_,10);
  219.     dec(_Ay_,6);
  220.  
  221.     if _ax_>319 then _ax_:=_ax_-320;
  222.     if _ax_<0 then _ax_:=_ax_+320;
  223.     if _Ay_>199 then _Ay_:=_Ay_-200;
  224.     if _Ay_<0 then _Ay_:=199+_Ay_;
  225.  
  226.     ww:=640; wh:=400;
  227.  
  228.     ComputeFramePara;
  229.     GenVert;
  230.     vWait;
  231.     ShowVScreen;
  232.   until keypressed;
  233.  
  234. end;
  235.  
  236. var k:word;
  237.  
  238. begin
  239.   LoadImage;
  240.   Vscr:=halloc(64016);
  241.   if (vscr=0) or (img=nil) then begin
  242.     writeln('Allocation error.');
  243.     hfree(vscr); free(img);
  244.     halt
  245.   end;
  246.   fillchar(mem[vscr:0],64000,0);
  247.   InitVideo;
  248.  
  249.   { precalculations }
  250.   for k:=0 to 255 do begin
  251.     SinTab[k]:=trunc(256*sin(2*pi*k/255));
  252.     CosTab[k]:=trunc(256*cos(2*pi*k/255));
  253.   end;
  254.  
  255.   for k:=0 to 199 do RowOffs[k]:=k*320;
  256.  
  257.   DoIt;
  258.  
  259.   TextMode(C80);
  260.   free(img);
  261.   hfree(Vscr);
  262. end.
  263.